/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package airacrobats.game.object;

import airacrobats.io.data.AirplaneData;
import airacrobats.io.data.FlapsData;
import airacrobats.io.data.GhostData;
import airacrobats.io.data.JWavefrontModel;
import airacrobats.sound.Sound3D;
import java.util.ArrayList;
import java.util.List;
import javax.sound.sampled.LineUnavailableException;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

/**
 * This type of airplane is an airplane that follow the ghosts steps given on the constructor.
 */
public class GhostAirplane extends Airplane
{
    /**
     * The list of ghost steps to be followed by this airplane.
     */
    private List<GhostData> ghosts;

    /**
     * @param model The model.
     * @param shadowModel The shadow model.
     * @param flapsModels The airplane flaps.
     * @param propellerModel The propeller model.
     * @param flapsDataList The flaps data.
     * @param position The initial position.
     * @param airplaneData The airplane data.
     * @param speedVector The initial speed vector.
     * @param inverted Inverted flag.
     * @param engineSounds The engine sounds.
     * @param ghosts The ghosts.
     */
    public GhostAirplane(JWavefrontModel model, JWavefrontModel shadowModel, 
            JWavefrontModel[] flapsModels, JWavefrontModel propellerModel, FlapsData[] flapsDataList, Point3f position,
            AirplaneData airplaneData, Vector3f speedVector, boolean inverted,
            Sound3D[] engineSounds, List<GhostData> ghosts)
    {
        super(model, shadowModel, flapsModels, propellerModel, flapsDataList, position, airplaneData, speedVector, inverted, engineSounds);
        this.ghosts = new ArrayList<GhostData>(ghosts);
    }

    /**
     */
    @Override
    protected void doUpdate(long deltaTime, long time, Point3f cameraPosition) throws LineUnavailableException
    {       
        GhostData ghostData = null;
        while (!ghosts.isEmpty() && time >= ghosts.get(0).getTime())
        {
            ghostData = ghosts.remove(0);
        }

        if (ghostData != null)
        {
            rQuaternion = ghostData.getQuaternion();
            position = ghostData.getPosition();
            smokeOn = ghostData.isSmokeOn();
        }
    }
}
